// /pages/team-list/team-list.js
import { getProjectLeaderList, setProjectLeaderDelete } from '../../api/pay'
import user from '../../../utils/user'
import { confirm } from '../../../utils/util'
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list:[],
        projectId:'',
        userId:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.setData({
        projectId:options.id,
        userId:user.userId
      })
    },
    onShow() {
        this.getProjectLeaderList()
    },
    // 拿到列表
    async getProjectLeaderList () {
        const result = await getProjectLeaderList({
            projectId:this.data.projectId
        })
        this.setData({
            list:result
        })
    },
    // 邀请人员管理项目
    onShareAppMessage() {
        return {
            title: user.userName + '邀请您加入「' + (this.data.projectName || user.companyName) + '」' + (this.data.projectName ? '名单管理' : '项目'),
            path: '/pages/index/index?scene=' + encodeURIComponent('uId=' + user.userId + '&cId=' + user.companyId + (this.data.projectId ?
                ('&pId=' + this.data.projectId) : '')),
            imageUrl: '../../assets/img/resident/share.png'
        }
    },
    async setProjectLeaderDelete (event) {
        const { id } = event.currentTarget.dataset
        console.log(id, '移除管理员id')
        confirm('是否移除该管理').then(async () => {
            await setProjectLeaderDelete({
                projectId:this.data.projectId,
                id:id
            })
            await this.getProjectLeaderList()
        })
        
    }
})